package cn.com.se.sharepictrue.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.List;

import cn.com.se.sharepictrue.R;
import cn.com.se.sharepictrue.bean.UserInfoBean;
import cn.com.se.sharepictrue.business.ImageLoader;
import cn.com.se.sharepictrue.quickadapter.BaseAdapterHelper;
import cn.com.se.sharepictrue.quickadapter.MultiViewTypeSupport;
import cn.com.se.sharepictrue.quickadapter.QuickAdapter;
import cn.com.se.sharepictrue.utils.StringUtils;

/**
 * Created by KIDNG on 2015/12/16.
 */
public class BanUserAdapter extends QuickAdapter<UserInfoBean> {
    private Context mContext;

    public BanUserAdapter(Context context, int layoutResId) {
        super(context, layoutResId);
        mContext = context;
    }

    public BanUserAdapter(Context context, int layoutResId, List<UserInfoBean> data) {
        super(context, layoutResId, data);
        mContext = context;
    }

    public BanUserAdapter(Context context, List<UserInfoBean> data, MultiViewTypeSupport<UserInfoBean> multiViewTypeSupport) {
        super(context, data, multiViewTypeSupport);
        mContext = context;
    }

    @Override
    protected void convert(final BaseAdapterHelper helper, final UserInfoBean item) {
        Button banBtn = helper.getView(R.id.btn_person_list_concern);
        if (item.getIsAllow().equals(UserInfoBean.IS_ALLOW)) {
            banBtn.setSelected(true);
            banBtn.setText(mContext.getResources().getString(R.string.manager_user_ban));
        } else {
            banBtn.setSelected(false);
            banBtn.setText(mContext.getResources().getString(R.string.manager_user_cancel_ban));
        }
        banBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnBanListener != null) {
                    mOnBanListener.onBan(helper, item);
                }
            }
        });
        helper.setText(R.id.tv_person_list_name, item.getUserName());
        helper.setText(R.id.tv_person_list_introduction, item.getSighature());
        if (StringUtils.isEmpty(item.getPortrait()) || item.getPortrait().length() < 26)
            helper.setImageResource(R.id.civ_person_list_avatar,R.mipmap.bg_drawer);
        else
            ImageLoader.getInstance(mContext).load((ImageView) (helper.getView(R.id.civ_person_list_avatar)), item.getPortrait(),R.mipmap.bg_drawer);
    }

    public void setOnBanListener(OnBanListener onBanListener) {
        mOnBanListener = onBanListener;
    }

    private OnBanListener mOnBanListener;

    public interface OnBanListener {
        void onBan(BaseAdapterHelper helper, UserInfoBean item);
    }
}
